<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <label class="el-form-item-label">客户编号</label>
        <el-input v-model="query.custNo" clearable placeholder="客户编号" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">客户名称</label>
        <el-input v-model="query.custName" clearable placeholder="客户名称" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">地区</label>
        <el-input v-model="query.custRegion" clearable placeholder="地区" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">客户经理</label>
        <el-input v-model="query.custManagerName" clearable placeholder="客户经理" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">客户等级</label>
        <el-input v-model="query.custLevelLabel" clearable placeholder="客户等级" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">客户状态</label>
        <el-input v-model="query.custStatus" clearable placeholder="客户状态" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <rrOperation :crud="crud" />
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
          <el-form-item label="客户名称" prop="custName">
            <el-input v-model="form.custName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="地区" prop="custRegion">
            <el-select v-model="form.custRegion" filterable placeholder="请选择">
              <el-option
                v-for="item in dict.cust_region"
                :key="item.id"
                :label="item.label"
                :value="item.value" />
            </el-select>
          </el-form-item>
          <el-form-item label="客户经理编号" prop="custManagerId">
            <el-input v-model="form.custManagerId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="客户经理" prop="custManagerName">
            <el-input v-model="form.custManagerName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="客户等级" prop="custLevelLabel">
            <el-select v-model="form.custLevelLabel" filterable placeholder="请选择">
              <el-option
                v-for="item in dict.cust_level"
                :key="item.id"
                :label="item.label"
                :value="item.value" />
            </el-select>
          </el-form-item>
          <el-form-item label="满意度" prop="custSatisfy">
            <el-select v-model="form.custSatisfy" filterable placeholder="请选择">
              <el-option
                v-for="item in dict.cust_satisfy"
                :key="item.id"
                :label="item.label"
                :value="item.value" />
            </el-select>
          </el-form-item>
          <el-form-item label="信用度" prop="custCredit">
            <el-input v-model="form.custCredit" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="地址" prop="custAddr">
            <el-input v-model="form.custAddr" :rows="3" type="textarea" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="邮政编码" prop="custZip">
            <el-input v-model="form.custZip" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="电话" prop="custTel">
            <el-input v-model="form.custTel" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="传真" prop="custFax">
            <el-input v-model="form.custFax" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="网址" prop="custWebsite">
            <el-input v-model="form.custWebsite" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="营业执照注册号" prop="custLicenceNo">
            <el-input v-model="form.custLicenceNo" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="法人" prop="custChieftain">
            <el-input v-model="form.custChieftain" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="注册资金">
            <el-input v-model="form.custBankroll" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="年营业额">
            <el-input v-model="form.custTurnover" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="开户银行" prop="custBank">
            <el-input v-model="form.custBank" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="银行账号" prop="custBankAccount">
            <el-input v-model="form.custBankAccount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="地税登记号">
            <el-input v-model="form.custLocalTaxNo" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="国税登记号">
            <el-input v-model="form.custNationalTaxNo" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="客户状态" prop="custStatus">
            <el-select v-model="form.custStatus" filterable placeholder="请选择">
              <el-option
                v-for="item in dict.cust_status"
                :key="item.id"
                :label="item.label"
                :value="item.value" />
            </el-select>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column prop="custNo" label="客户编号" />
        <el-table-column prop="custName" label="客户名称" />
        <el-table-column prop="custRegion" label="地区">
          <template slot-scope="scope">
            {{ dict.label.cust_region[scope.row.custRegion] }}
          </template>
        </el-table-column>
        <el-table-column prop="custManagerId" label="客户经理编号" />
        <el-table-column prop="custManagerName" label="客户经理" />
        <el-table-column prop="custLevelLabel" label="客户等级">
          <template slot-scope="scope">
            {{ dict.label.cust_level[scope.row.custLevelLabel] }}
          </template>
        </el-table-column>
        <el-table-column prop="custSatisfy" label="满意度">
          <template slot-scope="scope">
            {{ dict.label.cust_satisfy[scope.row.custSatisfy] }}
          </template>
        </el-table-column>
        <el-table-column prop="custCredit" label="信用度" />
        <el-table-column prop="custAddr" label="地址" />
        <el-table-column prop="custZip" label="邮政编码" />
        <el-table-column prop="custTel" label="电话" />
        <el-table-column prop="custFax" label="传真" />
        <el-table-column prop="custWebsite" label="网址" />
        <el-table-column prop="custLicenceNo" label="营业执照注册号" />
        <el-table-column prop="custChieftain" label="法人" />
        <el-table-column prop="custBankroll" label="注册资金" />
        <el-table-column prop="custTurnover" label="年营业额" />
        <el-table-column prop="custBank" label="开户银行" />
        <el-table-column prop="custBankAccount" label="银行账号" />
        <el-table-column prop="custLocalTaxNo" label="地税登记号" />
        <el-table-column prop="custNationalTaxNo" label="国税登记号" />
        <el-table-column prop="custStatus" label="客户状态">
          <template slot-scope="scope">
            {{ dict.label.cust_status[scope.row.custStatus] }}
          </template>
        </el-table-column>
        <el-table-column v-if="checkPer(['admin','cstCustomer:edit','cstCustomer:del'])" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudCstCustomer from '@/api/cstCustomer'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'

const defaultForm = { custNo: null, custName: null, custRegion: null, custManagerId: null, custManagerName: null, custLevelLabel: null, custSatisfy: null, custCredit: null, custAddr: null, custZip: null, custTel: null, custFax: null, custWebsite: null, custLicenceNo: null, custChieftain: null, custBankroll: null, custTurnover: null, custBank: null, custBankAccount: null, custLocalTaxNo: null, custNationalTaxNo: null, custStatus: null }
export default {
  name: 'CstCustomer',
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  dicts: ['cust_region', 'cust_level', 'cust_satisfy', 'cust_status'],
  cruds() {
    return CRUD({ title: '客户信息管理', url: 'api/cstCustomer', idField: 'custNo', sort: 'custNo,desc', crudMethod: { ...crudCstCustomer }})
  },
  data() {
    return {
      permission: {
        add: ['admin', 'cstCustomer:add'],
        edit: ['admin', 'cstCustomer:edit'],
        del: ['admin', 'cstCustomer:del']
      },
      rules: {
        custName: [
          { required: true, message: '客户名称不能为空', trigger: 'blur' }
        ],
        custRegion: [
          { required: true, message: '地区不能为空', trigger: 'blur' }
        ],
        custManagerId: [
          { required: true, message: '客户经理编号不能为空', trigger: 'blur' }
        ],
        custManagerName: [
          { required: true, message: '客户经理不能为空', trigger: 'blur' }
        ],
        custLevelLabel: [
          { required: true, message: '客户等级不能为空', trigger: 'blur' }
        ],
        custSatisfy: [
          { required: true, message: '满意度不能为空', trigger: 'blur' }
        ],
        custCredit: [
          { required: true, message: '信用度不能为空', trigger: 'blur' }
        ],
        custAddr: [
          { required: true, message: '地址不能为空', trigger: 'blur' }
        ],
        custZip: [
          { required: true, message: '邮政编码不能为空', trigger: 'blur' }
        ],
        custTel: [
          { required: true, message: '电话不能为空', trigger: 'blur' }
        ],
        custFax: [
          { required: true, message: '传真不能为空', trigger: 'blur' }
        ],
        custWebsite: [
          { required: true, message: '网址不能为空', trigger: 'blur' }
        ],
        custLicenceNo: [
          { required: true, message: '营业执照注册号不能为空', trigger: 'blur' }
        ],
        custChieftain: [
          { required: true, message: '法人不能为空', trigger: 'blur' }
        ],
        custBank: [
          { required: true, message: '开户银行不能为空', trigger: 'blur' }
        ],
        custBankAccount: [
          { required: true, message: '银行账号不能为空', trigger: 'blur' }
        ],
        custStatus: [
          { required: true, message: '客户状态不能为空', trigger: 'blur' }
        ]
      },
      queryTypeOptions: [
        { key: 'custNo', display_name: '客户编号' },
        { key: 'custName', display_name: '客户名称' },
        { key: 'custRegion', display_name: '地区' },
        { key: 'custManagerName', display_name: '客户经理' },
        { key: 'custLevelLabel', display_name: '客户等级' },
        { key: 'custStatus', display_name: '客户状态' }
      ]
    }
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }
  }
}
</script>

<style scoped>

</style>
